package com.ahao.aggregation.dialog;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CustomPaymentDialog {

    public interface PaymentResultListener {
        void onPaymentSuccess();
        void onPaymentFailure();
    }

    public static void showPaymentDialog(Context context, String htmlContent, final PaymentResultListener listener) {
        // 创建一个线性布局
        LinearLayout layout = new LinearLayout(context);
        layout.setOrientation(LinearLayout.VERTICAL);

        // 创建 TextView 用于展示 HTML 信息
        final TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER_HORIZONTAL);
        textView.setText(Html.fromHtml(htmlContent));
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        layout.addView(textView);

        // 创建对话框
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("支付")
                .setView(layout)
                .setPositiveButton("成功", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        listener.onPaymentSuccess();
                    }
                })
                .setNegativeButton("失败", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        listener.onPaymentFailure();
                    }
                })
                .setCancelable(false);  // 不可点击对话框外部取消

        // 显示对话框
        AlertDialog dialog = builder.create();
        dialog.show();
    }
}
